package com.ruoyi.project.system.activitytype.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.activitytype.domain.ActivityType;
import com.ruoyi.project.system.activitytype.service.IActivityTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻分类Controller
 *
 * @autor LCL
 * @date - 2020/8/24
 */
@Controller
@RequestMapping("/system/activitytype")
public class ActivityTypeController extends BaseController {

    private String prefix = "system/activitytype";

    @Autowired
    private IActivityTypeService activityTypeService;

    @RequiresPermissions("system:activitytype:view")
    @GetMapping()
    public String activityType() {
        return prefix + "/activitytype";
    }

    /**
     * 查询新闻分类列表
     */
    @RequiresPermissions("system:activitytype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActivityType activityType) {
        startPage();
        List<ActivityType> list = activityTypeService.selectATList(activityType);
        return getDataTable(list);
    }

//    /**
//     * 导出新闻分类列表
//     */
//    @RequiresPermissions("system:type:export")
//    @Log(title = "新闻分类", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(ActivityType activityType)
//    {
//        List<ActivityType> list = activityTypeService.selectATList(activityType);
//        ExcelUtil<ActivityType> util = new ExcelUtil<ActivityType>(ActivityType.class);
//        return util.exportExcel(list, "type");
//    }

    /**
     * 新增新闻分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增新闻分类
     */
    @RequiresPermissions("system:activitytype:add")
    @Log(title = "新闻分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActivityType activityType)
    {
        return toAjax(activityTypeService.insertAT(activityType));
    }

    /**
     * 修改新闻分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ActivityType activityType = activityTypeService.selectATById(id);
        mmap.put("activityType", activityType);
        return prefix + "/edit";
    }

    /**
     * 修改新闻分类
     */
    @RequiresPermissions("system:activitytype:edit")
    @Log(title = "新闻分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActivityType activityType)
    {
        return toAjax(activityTypeService.updateAT(activityType));
    }

    /**
     * 删除新闻分类
     */
    @RequiresPermissions("system:activitytype:remove")
    @Log(title = "新闻分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(activityTypeService.deleteATByIds(ids));
    }

}
